﻿using SuperSocket.Command;
using SuperSocket.ProtoBase;

namespace Example.Command.Kernel;

public class AsyncFilterAttribute : AsyncCommandFilterAttribute
{
    //在命令执行前被调用
    public override async ValueTask<bool> OnCommandExecutingAsync(CommandExecutingContext txt)
    {
        if (txt.Package is StringPackageInfo pack)
        {
            Console.WriteLine($"client: {txt.Session.RemoteEndPoint}, command: {pack.Key}");
        }

        await Task.Delay(0);
        return true;
    }

    //在命令执行后被调用
    public override async ValueTask OnCommandExecutedAsync(CommandExecutingContext commandContext)
    {
        await Task.Delay(0);
    }
}